import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
// import About from '../views/AboutView.vue'



/* 
  admin用户的页面
*/

import AdminHomeView from '@/views/admin/AdminHome.vue'

import AccountManageView from '@/views/admin/accountManage/AccountManageView.vue'
import AddAccountView from '@/views/admin/accountManage/AddAccountView.vue'
import UpdateInfoView from '@/views/admin/accountManage/UpdateInfoView.vue'

import DefaultDBManageView from '@/views/admin/defaultTable/DefaultDBManageView.vue'
import AddDataView from '@/views/admin/defaultTable/AddDataView.vue'

import DefaultSetManageView from '@/views/admin/defaultSet/DefaultSetManageView.vue'
// 系统默认题集
import A_QuerySetView from '@/views/admin/defaultSet/proSet/QuerySetView.vue'
import A_AddSetView from '@/views/admin/defaultSet/proSet/AddSetView.vue'
import A_UpdateSetView from '@/views/admin/defaultSet/proSet/UpdateSetView.vue'
import A_DeleteSetView from '@/views/admin/defaultSet/proSet/DeleteSetView.vue'
//在默认题集添加题目
import A_AddQueryProView from '@/views/admin/defaultSet/addPro/AddQueryProView.vue'
import A_AddAddProView from '@/views/admin/defaultSet/addPro/AddAddProView.vue'
import A_AddUpdateProView from '@/views/admin/defaultSet/addPro/AddUpdateProView.vue'
import A_AddDeleteProView from '@/views/admin/defaultSet/addPro/AddDeleteProView.vue'
//在默认题集修改题目
import A_ModifyQueryProView from '@/views/admin/defaultSet/modifyPro/ModifyQueryProView.vue'
import A_ModifyAddProView from '@/views/admin/defaultSet/modifyPro/ModifyAddProView.vue'
import A_ModifyUpdateProView from '@/views/admin/defaultSet/modifyPro/ModifyUpdateProView.vue'
import A_ModifyDeleteProView from '@/views/admin/defaultSet/modifyPro/ModifyDeleteProView.vue'


/* 
  student用户的页面
*/

import StudentHomeView from '@/views/student/StudentHome.vue'


import SystemSetView from '@/views/student/systemSet/SystemSetView.vue'
import S_QuerySetView from '@/views/student/systemSet/defaultProSet/QuerySetView.vue'
import S_AddSetView from '@/views/student/systemSet/defaultProSet/AddSetView.vue'
import S_UpdateSetView from '@/views/student/systemSet/defaultProSet/UpdateSetView.vue'
import S_DeleteSetView from '@/views/student/systemSet/defaultProSet/DeleteSetView.vue'


import MyClassView from '@/views/student/myClass/MyClassView.vue'
import ClassSetView from '@/views/student/myClass/ClassSetView.vue'
import S_SetProfileView from '@/views/student/myClass/SetProfileView.vue'
import C_AnsProView from '@/views/student/myClass/AnsProView.vue'


import AnswerProView from'@/views/student/AnswerProView.vue'




/* 
  teacher用户的页面
*/
import TeacherHomeView from '@/views/teacher/TeacherHome.vue'

import SetManageView from '@/views/teacher/setManage/SetManageView.vue'
import SetProfileView from '@/views/teacher/setManage/SetProfileView.vue'
import AddSetView from '@/views/teacher/setManage/AddSetView.vue'
import AddProView from '@/views/teacher/setManage/AddProView.vue'

import ClassManageView from '@/views/teacher/classManage/ClassManageView.vue'
import ClassProfileView from '@/views/teacher/classManage/ClassProfileView.vue'
import T_ClassSetView  from  '@/views/teacher/classManage/ClassSetView.vue'
import AddClassView from '@/views/teacher/classManage/AddClassView.vue'
import AddStudentView from '@/views/teacher/classManage/AddStudentView.vue'
import PublishSetView from '@/views/teacher/classManage/PublishSetView.vue'

import DefaultTableView from  '@/views/teacher/defaultDB/DefaultTableView.vue'



/*
  commons
*/

import NotFoundView from "@/views/commons/NotFoundView.vue"
import LoginView from '@/views/commons/LoginView.vue'
import RegisterView from '@/views/commons/RegisterView.vue'
import ResetPasswordView from '@/views/commons/ResetPasswordView'
import store from '@/store/index'

const routes = [
  {
    //登录页面默认为首页
    path: '/',    
    name: 'login',
    component: LoginView,
    meta : {    //是否需要授权
        requestAuth : false,
    }
  },
  {
    //登录页面
    path: '/login',    
    name: 'login',
    component: LoginView,
    meta : {    //是否需要授权
        requestAuth : false,
    }
  },
  {
    //注册页面
    path: '/register',
    name: 'register',
    component: RegisterView,
    meta : {    
      requestAuth : false,
    }
  },
  {
    //密码重置页面
    path: '/resetPassword',
    name: 'resetPassword',
    component: ResetPasswordView,
    meta : {    
      requestAuth : false,
    }
  },
  {
    path: '/',
    redirect: '/login'
  },
  {
    //系统首页
    path: '/sls',
    name: 'home',
    component: HomeView,
    meta : {    
      requestAuth : true,
  }
  },
  // {
  //   //about页面
  //   path: '/sls/about',
  //   name: 'about',
  //   component: About,
  //   meta : {  
  //     requestAuth : true,
  // }
  // },

  
  {
    //admin首页
    path: '/sls/admin',
    name: 'adminHome',
    component: AdminHomeView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin用户管理
    path: '/sls/admin/accountManage',
    name: 'accountManage',
    component: AccountManageView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin用户信息修改
    path: '/sls/admin/updateInfo/:id',
    name: 'updateInfo',
    component: UpdateInfoView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin添加用户
    path: '/sls/admin/addAccount',
    name: 'addAccount',
    component: AddAccountView,
    meta : {    
      requestAuth : true,
    }
  },


  {
    //admin默认数据库管理
    path: '/sls/admin/defaultDBManage',
    name: 'defaultDBManage',
    component: DefaultDBManageView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin添加数据
    path: '/sls/admin/addData',
    name: 'addData',
    component: AddDataView,
    meta : {    
      requestAuth : true,
    }
  },



  {
    //admin默认题集管理
    path: '/sls/admin/defaultSetManage',
    name: 'defaultSetManage',
    component: DefaultSetManageView,
    meta : {    
      requestAuth : true,
    }
  },


  {
    //admin默认查询类题集
    path: '/sls/admin/defaultSetManage/querySet/:proType',
    name: 'A_querySet',
    component: A_QuerySetView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin在默认查询类题集添加题目
    path: '/sls/admin/defaultSetManage/querySet/addPro/:proType',
    name: 'A_addQuerySet',
    component: A_AddQueryProView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin在默认查询类题集修改题目
    path: '/sls/admin/defaultSetManage/querySet/modifyPro/:id',
    name: 'A_modifyQuerySet',
    component: A_ModifyQueryProView,
    meta : {    
      requestAuth : true,
    }
  },


  {
    //admin默认添加类题集
    path: '/sls/admin/defaultSetManage/addSet/:proType',
    name: 'A_addSet',
    component:A_AddSetView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin在默认添加类题集添加题目
    path: '/sls/admin/defaultSetManage/addSet/addPro/:proType',
    name: 'A_addAddSet',
    component: A_AddAddProView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin在默认添加类题集修改题目
    path: '/sls/admin/defaultSetManage/addSet/modifyPro/:id',
    name: 'A_modifyAddSet',
    component: A_ModifyAddProView,
    meta : {    
      requestAuth : true,
    }
  },


  {
    //admin默认修改类题集
    path: '/sls/admin/defaultSetManage/updateSet/:proType',
    name: 'A_updateSet',
    component: A_UpdateSetView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin在默认修改类题集添加题目
    path: '/sls/admin/defaultSetManage/updateSet/addPro/:proType',
    name: 'A_addUpdateSet',
    component: A_AddUpdateProView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin在默认修改类题集修改题目
    path: '/sls/admin/defaultSetManage/updateSet/modifyPro/:id',
    name: 'A_modifyUpdateSet',
    component: A_ModifyUpdateProView,
    meta : {    
      requestAuth : true,
    }
  },


  {
    //admin默认删除类题集
    path: '/sls/admin/defaultSetManage/deleteSet/:proType',
    name: 'A_deleteSet',
    component: A_DeleteSetView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin在默认删除类题集添加题目
    path: '/sls/admin/defaultSetManage/deleteSet/addPro/:proType',
    name: 'A_addDeleteSet',
    component: A_AddDeleteProView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //admin在默认删除类题集修改题目
    path: '/sls/admin/defaultSetManage/deleteSet/modifyPro/:id',
    name: 'A_modifyDeleteSet',
    component: A_ModifyDeleteProView,
    meta : {    
      requestAuth : true,
    }
  },




  
  {
    //teacher首页
    path: '/sls/teacher',
    name: 'teacherHome',
    component: TeacherHomeView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //teacher班级管理
    path: '/sls/teacher/classManage',
    name: 'classManage',
    component: ClassManageView,
    meta : {    
      requestAuth : true,
    }
  },

  {
    //teacher班级详情页
    path: '/sls/teacher/classManage/classProfile/:classId',
    name: 'classProfile',
    component: ClassProfileView,
    meta : {    
      requestAuth : true,
    }
  },

  {
    //teacher班级题集管理
    path: '/sls/teacher/classManage/classSet/:classId',
    name: 'T_classSet',
    component: T_ClassSetView,
    meta : {    
      requestAuth : true,
    }
  },

  {
    //teacher添加班级页
    path: '/sls/teacher/classManage/addClass/:teacherId',
    name: 'addClass',
    component: AddClassView,
    meta : {    
      requestAuth : true,
    }
  },

  {
    //teacher添加学生到当前班级
    path: '/sls/teacher/classManage/addStudent/:classId',
    name: 'addStudent',
    component: AddStudentView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //teacher添加题集到当前班级
    path: '/sls/teacher/classManage/publishSet/:classId',
    name: 'publishSet',
    component: PublishSetView,
    meta : {    
      requestAuth : true,
    }
  },

  
  {
    //teacher题集管理
    path: '/sls/teacher/setManage',
    name: 'setManage',
    component: SetManageView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //teacher题集详情
    path: '/sls/teacher/setManage/setProfile/:setId',  //通过题集id获取题集详细信息
    name: 'setProfile',
    component: SetProfileView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //teacher添加题集
    path: '/sls/teacher/setManage/addSet',
    name: 'addSet',
    component: AddSetView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //teacher添加题目
    path: '/sls/teacher/setManage/addPro/:setId',
    name: 'T_AddPro',
    component: AddProView,
    meta : {    
      requestAuth : true,
    }
  },

  {
    //teacher默认表管理
    path: '/sls/teacher/defaultTable',
    name: 'defaultTable',
    component: DefaultTableView,
    meta : {    
      requestAuth : true,
    }
  },




  {
    //student首页
    path: '/sls/student',
    name: 'studentHome',
    component: StudentHomeView,
    meta : {    
      requestAuth : true,
    }
  },

  {
    //系统题集页面
    path: '/sls/student/systemSet',
    name: 'systemSet',
    component: SystemSetView,
    meta : {    
      requestAuth : true,
    }
  },

  {
    //student默认查询类题集
    path: '/sls/student/systemSet/querySet/:proType',
    name: 'S_querySet',
    component: S_QuerySetView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //student默认插入类题集
    path: '/sls/student/systemSet/addSet/:proType',
    name: 'S_addSet',
    component: S_AddSetView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //student默认修改类题集
    path: '/sls/student/systemSet/updateSet/:proType',
    name: 'S_updateSet',
    component: S_UpdateSetView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //student默认删除类题集
    path: '/sls/student/systemSet/deleteSet/:proType',
    name: 'S_deleteSet',
    component: S_DeleteSetView,
    meta : {    
      requestAuth : true,
    }
  },

  {
    //学生答题页面
    path: '/sls/student/answerPro/:id',
    name: 'answerPro',
    component: AnswerProView,
    meta : {    
      requestAuth : true,
    }
  },



  {
    //我的班级页面
    path: '/sls/student/myClass',
    name: 'myClass',
    component: MyClassView,
    meta : {    
      requestAuth : true,
    }
  },

  {
    //班级题集页面
    path: '/sls/student/myClass/classSet/:classId',
    name: 'S_classSet',
    component: ClassSetView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //班级题集详情页面
    path: '/sls/student/myClass/setProfile/:setId',
    name: 'S_setProfile',
    component: S_SetProfileView,
    meta : {    
      requestAuth : true,
    }
  },
  {
    //班级题集答题页面
    path: '/sls/student/myClass/ansPro/:id',
    name: 'C_ansPro',
    component: C_AnsProView,
    meta : {    
      requestAuth : true,
    }
  },





  {
    //出错页面
    path: '/sls/404',
    name: 'notFound',
    component: NotFoundView,
    meta : {    
      requestAuth : false,
  }
  },
  {
    //如果是/sls/下的其他请求,则映射到404页面
    path: '/sls/:catchAll(.*)',
    redirect: '/sls/404'
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes
})


router.beforeEach((to, from, next) => {
  if (to.meta.requestAuth && !store.state.user.is_login) {
    next({ name: "login" });
  } else {
    next();
  }
})


// router.beforeEach( (to,from,next) =>{  //实现前端页面授权

//   let jwt_token = localStorage.getItem('item');
//   if(jwt_token){
//     store.dispatch('getInfo', jwt_token);
//     next();
//   }else{
//     if(to.meta.requestAuth && !store.state.user.is_login){
//       next({name : 'login'});   //如果是需要授权页面, 则跳转到登录页面
//    }
//    else{
//      next();
//    }
//   }

// })


export default router



// {
//   //admin默认查询类题集添加题目
//   path: '/sls/admin/defaultSetManage/querySet/addPro',
//   name: 'A_addPro',
//   component: A_AddQueryProView,
//   meta : {    
//     requestAuth : true,
//   }
// },
